package com.xh.bussiness.resource.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.resource.bean.request.WrongLogRequest;
import com.xh.bussiness.resource.dao.WrongLogMapper;
import com.xh.bussiness.resource.model.WrongLog;
import com.xh.bussiness.resource.service.IWrongLogService;
import com.xh.core.bean.XhPage;
import com.xh.core.service.impl.BaseServiceImpl;
import com.xh.core.util.StringUtils;

/**
 * <p>
 * 报错日志 服务实现类
 * </p>	
 *
 * @author JQM
 * @since 2019-08-27
 */
@Service
public class WrongLogServiceImpl extends BaseServiceImpl<WrongLogMapper, WrongLog> implements IWrongLogService {
    @Override
    public XhPage queryWrongLogPage(XhPage page, WrongLogRequest bean) {
        QueryWrapper qw=new QueryWrapper<WrongLog>();
        //拼装条件
        qw=prepareParams(bean, qw);

        if(bean.getCityId() != null){
        	qw.eq("city_id", bean.getCityId());
        }
        if(bean.getMaterialId() != null){
        	qw.eq("material_id", bean.getMaterialId());
        }
        if(bean.getSchoolId()!= null){
        	qw.eq("school_id", bean.getSchoolId());
        }
        if(bean.getTeachRoomId()!= null){
        	qw.eq("teach_room_id", bean.getTeachRoomId());
        }
        if(!StringUtils.isEmpty(bean.getTeacherName())){
        	qw.eq("creator_name", bean.getTeacherName());
        }
        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryWrongLog(WrongLogRequest bean) {
        QueryWrapper qw=new QueryWrapper<WrongLog>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(WrongLogRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        return qw;
    }
}
